[id].vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <!-- Page de détails d'un sous-domaine -->
  2. <template>
  3. <main>
  4. <LayoutContainer>
  5. <UiLoadingPanel v-if="pending" />
  6. <div v-else-if="subdomain !== null">
  7. <div>{{ $t('youRegisteredTheFollowingSubdomain') }} :</div>
  8. <div class="pa-8">
  9. <b>{{ subdomain.subdomain }}</b>
  10. <span class="text-on-neutral">.opentalent.fr</span>
  11. </div>
  12. <div>
  13. <div v-if="subdomain.active">
  14. <v-icon class="text-success icon small mr-2">
  15. fa-solid fa-check
  16. </v-icon>
  17. {{ $t('subdomainIsCurrentlyActive') }}
  18. </div>
  19. <div v-else>{{ $t('doYouWantToActivateThisSubdomain') }} ?</div>
  20. </div>
  21. <div class="mt-6 d-flex flex-row">
  22. <v-btn class="mr-12" @click="quit">
  23. {{ $t('back') }}
  24. </v-btn>
  25. <div v-if="!subdomain.active">
  26. <v-btn color="primary" @click="activateAndQuit">
  27. {{ $t('activate') }}
  28. </v-btn>
  29. </div>
  30. </div>
  31. </div>
  32. </LayoutContainer>
  33. </main>
  34. </template>
  35. <script setup lang="ts">
  36. import type { Ref } from 'vue'
  37. import Subdomain from '~/models/Organization/Subdomain'
  38. import { useEntityFetch } from '~/composables/data/useEntityFetch'
  39. import { useEntityManager } from '~/composables/data/useEntityManager'
  40. import { usePageStore } from '~/stores/page'
  41. import { TYPE_ALERT } from '~/types/enum/enums'
  42. import { useRefreshProfile } from '~/composables/data/useRefreshProfile'
  43. const { em } = useEntityManager()
  44. const { fetch } = useEntityFetch()
  45. const router = useRouter()
  46. const route = useRoute()
  47. const { refreshProfile } = useRefreshProfile()
  48. if (!route.params.id || /\d+/.test(route.params.id as string)) {
  49. throw new Error('no id found')
  50. }
  51. const id: number = parseInt(route.params.id as string)
  52. const { data: subdomain, pending } = fetch(Subdomain, id)
  53. const activationPending: Ref<boolean> = ref(false)
  54. const pageStore = usePageStore()
  55. const activateAndQuit = async () => {
  56. activationPending.value = true
  57. pageStore.loading = true
  58. await em.patch(Subdomain, id, { active: true })
  59. await refreshProfile()
  60. usePageStore().addAlert(TYPE_ALERT.SUCCESS, [
  61. 'subdomain_activated_and_available_in_a_few_minutes',
  62. ])
  63. quit()
  64. }
  65. const quit = () => {
  66. router.push('/parameters/website')
  67. activationPending.value = false
  68. pageStore.loading = false
  69. }
  70. </script>